package com.example.conference.controller;

import com.example.conference.domain.*;
import com.example.conference.domain.dto.PageParam;
import com.example.conference.service.CourseStudentServiceImpl;
import com.example.conference.service.CourseTeacherServiceImpl;
import com.example.conference.service.UserServiceImpl;
import com.example.conference.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(originPatterns = "*",allowCredentials = "true")
@RequestMapping("/student")
public class StudentController {
    @Autowired
    CourseTeacherServiceImpl courseTeacherService;
    @Autowired
    CourseStudentServiceImpl courseStudentService;
    @Autowired
    UserServiceImpl userService;


    //查询学生可选课程（本专业，公开）
    @RequestMapping("/queryCourse/{userId}/{majorId}")
    public Result queryCourse(@RequestBody PageParam page,@PathVariable Integer majorId,@PathVariable Integer userId){
        return courseStudentService.queryCourseTeahcerByMajor(page,userId, majorId);}

    //学生选课
    @RequestMapping("/selectCourse")
    public Result addCourseStudent(@RequestBody CourseStudent courseStudent){
        return courseStudentService.addCourseStudent(courseStudent);}
    //学生退选
    @RequestMapping("/deleteCourse/{csId}")
    public Result deleteCourse(@PathVariable("csId") Integer csId){
        return courseStudentService.delete(csId);}

    //查询学生已选课程
    @RequestMapping("/querySelectedCourse/{studentId}")
    public Result querySelectedCourse(PageParam page, @PathVariable Integer studentId){ return courseStudentService.querySelectedCourse(page, studentId);}

    @ExceptionHandler
    public Result handlerException(Exception e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }
}
